﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using infoMngmntGUI.Control;
using System.Data;

namespace infoMngmntGUI.View
{
    /// <summary>
    /// Interaction logic for Doctor.xaml
    /// </summary>
    public partial class ViewAndOrderTests : IView
    {
        int pID, vID;
        public ViewAndOrderTests(int _pID,int _vId)
        {
            minimumAccess = Control.AccessManagement.UserType.DOCTOR;
            InitializeComponent();
            this.pID = _pID;
            this.vID = _vId;
            updateTests();
        }

        private void updateTests()
        {
            dataGrid.HorizontalScrollBarVisibility = ScrollBarVisibility.Visible;
            dataGrid.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
            dataGrid.AutoGenerateColumns = true;
            
            DataSet dataSet = new DataSet("Query Data Set");
            DataTable queryResults = DbConnection.getTests(vID);
            dataSet.Tables.Add(queryResults);
            dataGrid.ItemsSource = dataSet.Tables[0].DefaultView;
            PatientNameLabel.Content = DbConnection.getPatientName(pID);
        }

        public override string ToString()
        {
            return "Order Test";
        }

        /*
         * 
         */


         /*
         * 
         */
        private void orderTestButton_Click(object sender, RoutedEventArgs e)
        {
          
            string patientName = "The following tests have been ordered for the patient, " +
                PatientNameLabel.Content + ":";


            UIElementCollection checks = checkBoxes_grid.Children;

            for (int i = 0; i < checks.Count; i++)
            {
                Visual checkBox = (Visual)checks[i];
                if (checkBox is CheckBox)
                {
                   CheckBox checker = checkBox as CheckBox; 

                    if(checker.IsChecked == true){

                        string testName = (string)(checkBox as CheckBox).Content;
                        DbConnection.AddTest(vID, testName);
                        

                    }
                }
            }
            updateTests();
        }
    }
}
